﻿@model IEnumerable<Shop.Models.Category>

@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutList.cshtml";
}
<p>
    <button class="btn btn-default" id="btnCreate">添加</button>
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
      
        <th>操作</th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            <button class="btn btn-primary" onclick="editCata(@item.Id)">修改</button>
            @Html.ActionLink("删除", "Delete", new { id = item.Id },new {@class= "btn btn-danger",onclick="return confirm('确定要删除吗？')" })
            @*@Ajax.ActionLink("删除")*@
        </td>
    </tr>
}

</table>


@*添加修改窗口*@
<div class="modal fade" id="cateModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加</h4>
            </div>
            <div class="modal-body" >
               <iframe frameborder="0" src=""  name="editForm" style="width:100%;height:100%" ></iframe>
            </div>
           
        </div>
    </div>
</div>

@section scripts{
    <script>
        $(function () {
            // 添加按钮
            $('#btnCreate').click(function () {
                $('iframe').attr('src', '@Url.Action("create")');
                $('.modal-title').html("添加")
                $('#cateModal').modal('show')
            })

            // 修改操作
        })
        // 关闭窗口
        function closeModal() {
            $('#cateModal').modal('hide')
        }

        //打开修改窗口
        function editCata(id) {
            $('iframe').attr('src', '@Url.Action("Edit")' + '/' + id);
            $('.modal-title').html("修改")
             $('#cateModal').modal('show')
        }

    </script>
    
    }
